<template>
  <basic-container>
    <avue-crud
        v-if="tableOption"
        ref="avueCrud"
        v-bind="bindVal"
        v-on="onEvent"
        v-model:page="page"
        v-model="startForm">
      <template slot-scope="{type,size,row}" slot="menuBtn">

        <el-dropdown-item v-if="getBtnPermission('changeEnableBtn',row,null,false)"
                          icon="el-icon-edit" :size="size" @click.native="changeEnableState(row,0)&&1===row.isEnable"
                          :type="type">
          禁用
        </el-dropdown-item>
        <el-dropdown-item v-if="getBtnPermission('changeEnableBtn',row,null,false)"
                          icon="el-icon-edit" :size="size" @click.native="changeEnableState(row,1)&&1===row.isEnable"
                          :type="type">
          启用
        </el-dropdown-item>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import {createDynamicMixin} from "@/mixins/startCrud.js"
import {changeEnableState} from "@/api/tpp/thirdPartyPlatformPlayConfigApi";


const option = {}
option.name = "tpp/thirdPartyPlatformOrderRefundBackCall"

export default {
  mixins: [createDynamicMixin(option)],
  watch: {
    "form.isSub"(val) {
      let column = this.$refs.avueCrud.$refs.dialogForm.formOption.column;
      let subAppId = this.findObject(column, 'subAppId');
      let subMchId = this.findObject(column, 'subMchId');
      subAppId.display = val === 1
      subMchId.display = val === 1
    }
  },
  methods: {
    changeEnableState(row, state) {
      let data = {};
      data.id = row.id
      data.state = state;
      let msg = `是否【${state === 0 ? '禁用' : '启用'}】名称为${row.name}的第三方平台？`;
      this.$confirm(msg, '系统提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning'
      }).then(() => {
        return changeEnableState(data)
      }).then(res => {
        this.refreshChange();
      })

    }
  }
}
</script>

<style scoped>

</style>
